package stu.day9_day18;



/**
 * Definition for singly-linked list.
 * public class ListNode {
 *     int val;
 *     ListNode next;
 *     ListNode() {}
 *     ListNode(int val) { this.val = val; }
 *     ListNode(int val, ListNode next) { this.val = val; this.next = next; }
 * }
 */
class LeetCode328 {
    public ListNode oddEvenList(ListNode head) {

        if(head==null || head.next==null){
            return head;
        }
        ListNode  slow = head;
        ListNode  fast = head.next;
        ListNode  node1 = head.next;
        ListNode node = head.next.next;

        while (node!=null){
            slow.next = node;
            slow = slow.next;

            if(node.next!=null){
                node = node.next;
                fast.next = node;
                fast = fast.next;
            }
            node = node.next;
        }
        fast.next = null;
        slow.next = node1;
        return head;
    }
}